package CTRLayer;

import java.util.ArrayList;

import ModelLayer.*;
import DBLayer.*;

/**
 * Write a description of class PersonCtr here.
 * 
 * @author (your name)
 * @version (a version number or a date)
 */
public class PersonCtr {
	// instance variables - replace the example below with your own

	/**
	 * Constructor for objects of class PersonCtr
	 */
	public PersonCtr() {

	}

	public void createPerson(String name, String addresse, int zipCode,
			City city, String phone, String email, int personID,
			String customerType, String empPosition) {
		Person personObj = new Person();

		personObj.setName(name);
		personObj.setAddresse(addresse);
		personObj.setZipCode(zipCode);
		personObj.setCity(city);
		personObj.setPhone(phone);
		personObj.setEmail(email);
		personObj.setPersonID(personID);
		personObj.setCustomerType(customerType);
		personObj.setEmpPosition(empPosition);

		try {
			DbConnection1.startTransaction();
			DBPerson dbPerson = new DBPerson();
			dbPerson.insertPerson(personObj);
			DbConnection1.commitTransaction();
		} catch (Exception e) {
			DbConnection1.rollbackTransaction();
		}
	}

	public SalesOrder findBuys(int personID) {
		DBSalesOrder dbSalesOrder = new DBSalesOrder();
		SalesOrder result = dbSalesOrder.findSalesOrder(personID, false);
		return result;
	}

	public Person findPerson(int personID) {
		DBPerson dbPerson = new DBPerson();
		Person result = dbPerson.findPerson(personID, false);
		return result;
	}

	public void removePerson(int personID) {
		DBPerson dbPerson = new DBPerson();
		dbPerson.delete(personID);
	}


	public int updateCustomer(String name, String address, int zipcode,
			String customerType) {
		DBPerson dbPerson = new DBPerson();
		Person person = new Person();
		person.setName(name);
		person.setAddresse(address);
		person.setZipCode(zipcode);
		person.setCustomerType(customerType);
		return dbPerson.updatePerson(person);
	}

	public Person findEmployee(int employeeID) {
		DBPerson dbPerson = new DBPerson();
		Person result = dbPerson.findPerson(employeeID, false);
		return result;

	}

	public void removeEmployee(int employeeID) {
		DBPerson dbPerson = new DBPerson();
		dbPerson.delete(employeeID);
	}

	public int updateEmployee(String name, String address, int zipcode,
			String employeePosition) 
	{
		DBPerson dbPerson = new DBPerson();
		Person person = new Person();
		person.setName(name);
		person.setAddresse(address);
		person.setZipCode(zipcode);
		person.setEmpPosition(employeePosition);
		return dbPerson.updatePerson(person);
	}

	// public void addKunde(Arraylist kundeList){}
	// public void addMedarbejder(Arraylist medarbejderList){}

}
